<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>实物资产出库管理</title>
    <script charset="utf-8" src="../../../../../res/js/jquery-3.4.1.min.js"></script>
    <script charset="utf-8" src="../../../../../res/js/login_common.js"></script>
    <script charset="utf-8" src="../../../../../res/layui/layui.js"></script>
    <script charset="utf-8" src="../../../../../res/js/Tools.js"></script>
    <script charset="utf-8" src="../../../../../res/js/error.js"></script>
    <link href="../../../../../res/images/favicon.ico" rel="shortcut icon" type="image/x-icon">
    <link href="../../../../../res/layui/css/layui.css" media="all" rel="stylesheet">
</head>
<body style="padding: 10px">
<form action="" class="layui-form layui-form-pane">
    <input id="pkDeliverFromGodownId" name="pkDeliverFromGodownId" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">资产名</label>
        <div class="layui-input-block" lay-search>
            <select id="assetName" name="assetName" lay-search lay-verify="required">
                <option value="">请选择</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">

        <label class="layui-form-label">使用人</label>
        <div class="layui-input-block" lay-search>
            <select id="personnelId" name="personnelId" lay-search lay-verify="required">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class=" layui-form-item">
        <div class="layui-input-block" id="flows">
            <button class="layui-btn site-demo-active" lay-filter="demo1" lay-submit="" type="submit">立即提交
            </button>
            <input class="layui-btn layui-btn-primary" id="demo3" type="button" value="取消">
        </div>
    </div>
</form>

<script>
    var form = null;
    let pkDeliverFromGodownId = getQueryString("pkDeliverFromGodownId");
    // 修改赋值
    layui.use(['form', 'layer'], function () {
        layer = layui.layer
            , form = layui.form;
        //自定义

        loadPerson();
        if (pkDeliverFromGodownId) {
            findById(pkDeliverFromGodownId);
        } else {
            loadassetName();
        }
        form.render();


        //监听提交
        form.on('submit(demo1)', function (data) {
            let res = postAjax(getRootPath() + "OaDeliverFromGodownAction/fromGodownAddOrUpdate", data.field);
            if (res.code === 1) {
                layer.msg('操作成功3秒后关闭当前窗口', {icon: 1});
                setTimeout(function () {
                    formClose();
                }, 3000);
                setTimeout(function () {
                    parent.layui.table.reload('test');//刷新父页面
                    //window.parent.location.reload();//刷新父页面
                    const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 3001);
                //window.location.reload();//刷新页面
            } else if (res.code === 500) {

            } else {
                layer.msg("新增失败");
            }
            return false;
        });

        $("#demo3").on("click", function () {
            //询问框
            layer.confirm('是否关闭该页面？', {
                btn: ['是的', '取消'] //按钮
            }, function () {
                formClose();
                parent.layui.table.reload('test');//刷新父页面
                //window.parent.location.reload();//刷新父页面
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });
        });

    });

    function findById(pkDeliverFromGodownId) {
        let url = getRootPath() + "/OaDeliverFromGodownAction/deliverFromGodownFindById/" + pkDeliverFromGodownId;
        let data = getAjaxById(url);
        console.log(data);
        var url1 = getRootPath() + "OaAssetAction/selectAll?id=" + data.data.assetName;
        var data1 = getAjax(url1, null);
        $.each(data1.data, function (index, item) {
            $("#assetName").append("<option value='" + item.pkAssetId + "'>" + item.assetName + "(" + item.pkAssetId + ")" + "</option>");
        });
        $("#pkDeliverFromGodownId").val(data.data.pkDeliverFromGodownId);
        $("#assetName").val(data.data.assetName);
        $("#personnelId").val(data.data.personnelId);
        form.render("select");
    }

    function loadPerson() {
        var url = getRootPath() + "OaPersonnelAction/personnelFindByAll";
        var data = getAjax(url, null);
        $.each(data.data, function (index, item) {
            $("#personnelId").append("<option value='" + item.pkPersonnelId + "'>" + item.personnelName + "</option>");
        });
    }

    function loadassetName() {
        var url = getRootPath() + "/OaAssetAction/selectAll";
        var data = getAjax(url, null);
        $.each(data.data, function (index, item) {
            $("#assetName").append("<option value='" + item.pkAssetId + "'>" + item.assetName + "(" + item.pkAssetId + ")" + "</option>");
        });
    }


</script>
</body>
</html>